package com.asset.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.SpliteratorUtil;
import com.asset.common.ErrorCode;
import com.asset.constant.UserConstant;
import com.asset.exception.ThrowUtils;
import com.asset.model.dto.purchase.PurchaseQueryRequest;
import com.asset.model.entity.purchase.Purchase;
import com.asset.model.vo.AssetVO;
import com.asset.model.vo.LoginUserVO;
import com.asset.model.vo.PurchaseVo;
import com.asset.service.impl.PurchaseServiceImpl;
import com.github.pagehelper.PageInfo;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.annotation.WebServlet;
import java.security.acl.LastOwnerException;
import java.util.ArrayList;

@RestController
@RequestMapping("/purchase")
public class PurchaseController {
	@Autowired
	private PurchaseServiceImpl purchaseService;
	@PostMapping ("/getPurchase")
    public PageInfo<Purchase> purchase(@RequestBody PurchaseQueryRequest purchaseQueryRequest) {
		LoginUserVO loginUser = (LoginUserVO) StpUtil.getSession().get(UserConstant.USER_LOGIN_STATE);
		ThrowUtils.throwIf(loginUser == null, ErrorCode.NOT_LOGIN_ERROR);
		int companyId = loginUser.getCompanyId();
		//测试用得
		if (purchaseQueryRequest.getCompanyId()!=0) {
			purchaseQueryRequest.setCompanyId(companyId);
		}
		//正式用的
		purchaseQueryRequest.setCompanyId(companyId);

		PageInfo<Purchase>assetVOPageInfo = purchaseService.getPurchaseByCompanyAndAll(purchaseQueryRequest);
		return assetVOPageInfo;
	}
//	@PostMapping ("/addPurchase")
//	public  Object addPurchase(@RequestBody ArrayList<Purchase> purchaseList) {
//		LoginUserVO loginUser = (LoginUserVO) StpUtil.getSession().get(UserConstant.USER_LOGIN_STATE);
//		ThrowUtils.throwIf(loginUser == null, ErrorCode.NOT_LOGIN_ERROR);
//		int companyId = loginUser.getCompanyId();
//
//	}

}
